package org.cloud.jiangyoutourism.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.cloud.jiangyoucommon.common.Result;
import org.cloud.jiangyoucommon.utils.StringUtils;
import org.cloud.jiangyoutourism.entity.pojo.Sights;
import org.cloud.jiangyoutourism.mapper.SightsMapper;
import org.cloud.jiangyoutourism.service.SightsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;


/**
 * 景点信息  Service层实现类
 * @author liupy
 * @since 2024-01-07 16:05:12
 */
@Slf4j
@Service
public class SightsServiceImpl implements SightsService {
    @Autowired
    private SightsMapper sightsMapper;

    /**
     * 获取景点列表
     * @return
     */
    @Override
    public Result getAllSights() {
        List<Sights> sightsList = sightsMapper.selectList(new LambdaQueryWrapper<Sights>());

        if (CollectionUtils.isEmpty(sightsList)) {
            log.error("景点列表为空");
            return Result.fail("景点列表为空");
        }

        return Result.success(sightsList);
    }

    /**
     * 根据id查询景点信息
     * @param sightsId 景点id
     * @return
     */
    @Override
    public Result queryById(String sightsId) {
        Sights sights = sightsMapper.selectById(StringUtils.trim(sightsId));

        if (sights == null) {
            log.error("景点不存在，sightsId={}", sightsId);
            return Result.fail("景点不存在");
        }

        return Result.success(sights);
    }

    /**
     * 根据名称模糊查询景点信息
     * @param name 景点名称
     * @return
     */
    @Override
    public Result queryByUserName(String name) {
        List<Sights> sightsList = sightsMapper.selectList(new LambdaQueryWrapper<Sights>()
                .like(Sights::getSightsName, StringUtils.trim(name)));

        if (CollectionUtils.isEmpty(sightsList)) {
            return Result.fail("该账号不存在");
        }

        return Result.success(sightsList);
    }
}
